package com.cskaoyan.mall.product.controller;

import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.PlatformAttrInfoDTO;
import com.cskaoyan.mall.product.dto.PlatformAttrValueDTO;
import com.cskaoyan.mall.product.query.PlatformAttrInfoParam;
import com.cskaoyan.mall.product.service.PlatformAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Macro_Ray
 * @since 2024/6/6 下午10:13
 */
@RestController
@RequestMapping("/admin/product/")
public class PlatformAttrController {

    @Autowired
    PlatformAttrService platformAttrService;

    /**
     * 根据分类id 获取平台属性列表
     */
    // attrInfoList/2/13/61
    @GetMapping("attrInfoList/{firstLevelCategoryId}/{secondLevelCategoryId}/{thirdLevelCategoryId}")
    public Result<List<PlatformAttrInfoDTO>> getPlatformAttrInfoList(@PathVariable("firstLevelCategoryId") Long firstLevelCategoryId,
                                                                     @PathVariable("secondLevelCategoryId") Long secondLevelCategoryId,
                                                                     @PathVariable("thirdLevelCategoryId") Long thirdLevelCategoryId) {
        List<PlatformAttrInfoDTO> platformAttrInfoList = platformAttrService.getPlatformAttrInfoList(firstLevelCategoryId,
                secondLevelCategoryId, thirdLevelCategoryId);
        return Result.ok(platformAttrInfoList);
    }

    /**
     * 保存平台属性信息
     * */
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody PlatformAttrInfoParam platformAttrInfoParam) {
        platformAttrService.saveAttrInfo(platformAttrInfoParam);
        return Result.ok();
    }

    /**
     * 获取平台属性值列表
     * */
    @GetMapping("getAttrValueList/{attrId}")
    public Result<List<PlatformAttrValueDTO>> getPlatformAttrValueList(@PathVariable("attrId") Long attrId) {
        List<PlatformAttrValueDTO> platformAttrValueList = platformAttrService.getPlatformAttrValueList(attrId);
        return Result.ok(platformAttrValueList);
    }


}
